<?php
namespace app\admin\controller;

use app\common\entity\BackResult;
use app\common\service\AdminService;
use app\common\service\BannerService;
use app\Request;

/**
 * 表还是admin表 只不过角色是editor
 * Class Editor
 * @package app\admin\controller
 */
class Editor extends Base{

    public function one(){

    }

    //
    public function index(Request $request){
        $page = $request->param("page",1);
        $pageSize = $request->param('pageSize',10);
        $service = new AdminService();
        $where =[ ['roles','like','%editor%']];;//暂时用这种方法
        $data = $service->getList($page,$pageSize,$where);
        return BackResult::success($data);
    }

    public function create(Request $request){
        $post = $request->post();
        $service = new AdminService();
        if(empty($post['username'])){
            return BackResult::error([],"账号不能为空");
        }
        if(empty($post['name'])){
            return BackResult::error([],'名称不能为空');
        }
        $post['roles'] = 'editor';
        $data = $service->create($post);
        return BackResult::success($data);
    }

    public function update(Request $request){
        $post = $request->post();
        $service = new AdminService();
        $data = $service->update($post);
        return BackResult::success($data);
    }

    public function remove(Request $request){
        $id = $request->param("id");
        $service = new AdminService();
        $res = $service->del($id);
        return BackResult::success($res);
    }
}